<template>
	<view class="page">
			<view class="location">
				<image class="home-img" src="../../static/location.png"></image>
				<text class="home-title">巴谱美业～{{shop_name}}</text>
			</view>
		<view class="list">
		  <router-link to='pages/home/reservation_list/reservation_list'>
			<view class="list-top">
			   <image class="img-list" src="../../static/yuyue.png"></image>
			   <view >预约列表</view>
			</view>
			</router-link>
		<!--  <router-link to='pages/home/job_summary/summary_detail/summary_detail' @click.native.prevent="alertMessage">
			<view class="list-top">
			   <image class="img-list" src="../../static/gongzuo.png"></image>
			   <view>工作总结</view>
			</view>
		  </router-link> -->
		  <view class="list-top" @click.native="alertMessage">
		     <image class="img-list" src="../../static/gongzuo.png"></image>
		     <view>工作总结</view>
		  </view>
		 <router-link to='pages/home/order/order'>
			<view class="list-top">
			   <image class="img-list" src="../../static/dingdan.png"></image>
			   <view>订单</view>
			</view>
		  </router-link>
		
        <!--  <router-link to='pages/home/job_summary/job_summary' @click.native.prevent="alertMessage">
			<view class="list-top">
			   <image class="img-list" src="../../static/kaiqin.png"></image>
			   <view>考勤打卡</view>
			</view>
		   </router-link> -->
		   <view class="list-top" @click.native="alertMessage">
		      <image class="img-list" src="../../static/kaiqin.png"></image>
		      <view>考勤打卡</view>
		   </view>
		</view>
		
		<!-- 经营数据 -->
			<view class="statistical">
				<view class="statistical-title">
						<view class="data-title">待处理数据</view>
						<!--<text class="arrows">></text>-->
				</view>
				<view class="statistical-data">
					<text>{{reseve_need_count}}</text>
					<view>预约待处理</view>
				</view>
				<view class="statistical-data">
					<text>{{reseve_complate_month}}</text>
					<view>本月处理预约数</view>
				</view>
				<view class="statistical-data">
					<text>{{order_need_count}}</text>
					<view>订单待处理数</view>
				</view>
				<view class="statistical-data">
					<text>{{order_complate_month}}</text>
					<view>订单本月处理数</view>
				</view>
				<!--<view class="statistical-data">
					<text>{{profit}}</text>
					<view>利润</view>
				</view>
				<view class="statistical-data">
					<text>0.00</text>
					<view>实际收款金额</view>
				</view>
				<view class="statistical-data">
					<text>0.00</text>
					<view>会员消耗金额</view>
				</view>
				<view class="statistical-data">
					<text>0.00</text>
					<view>开卡充值金额</view>
				</view>
				<view class="statistical-data">
					<text>0.00</text>
					<view>服务产品金额</view>
				</view>-->
			</view>
		<!-- 店铺数据 -->
			<view class="statistical">
				<view class="statistical-title">
						<view class="data-title">店铺数据</view>
						<!--<text class="arrows">></text>-->
				</view>
				<view class="statistical-data">
					<text>{{newMemberDay}}</text>
					<view>本月新增会员数</view>
				</view>
				<view class="statistical-data">
					<text>{{memberNum}}</text>
					<view>会员总数</view>
				</view>
				<view class="statistical-data">
					<text>{{rechargeMonth}}</text>
					<view>本月会员卡充值总额</view>
				</view>
				<view class="statistical-data">
					<text>{{flowAccountMonth}}</text>
					<view>本月店铺流水总额</view>
				</view>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			flowAccount:0,//营业收入
			cost: 0,//成本
			profit: 0,//利润
			
			reseve_need_count: 0,//预约待处理
			reseve_complate_month:0,//本月处理预约数
			order_need_count: 0,//订单待处理数
			order_complate_month:0,//订单本月处理数
			shop_name:uni.getStorageSync('shop_name'),
			flowAccountMonth:0,//本月店铺流水总额
			rechargeMonth: 0,//本月会员卡充值总额
			newMemberDay: 0,//新增会员数
			memberNum: 0,//会员总数
			}
		},
		onShow(){
			if(uni.getStorageSync('admin_id')=="" || uni.getStorageSync('admin_id')==undefined){
				uni.navigateTo({
					url:'/pages/ucenter/login'
				})
			return false;
			}
			this.shop_name=uni.getStorageSync('shop_name');
			this.getShopCode();
			var dayStart=this.getDate('date');
			var dayEnd=this.getDate('date');
			this.getData(dayStart,dayEnd);
			this.getReserveData(dayStart);
			this.getAllMemberNum();
			
		},
		methods:{
			alertMessage(){
				uni.showToast({
					title:"功能暂未开放",
					icon:'none',
				    duration: 2000
				});
			},
			gotoarrow(){
				this.$router.go(-1)
			},getDate(type){
	
			   var myDate = new Date();
	
				//获取当前年
			   var year = myDate.getFullYear();
	
			   //获取当前月
			   var month = myDate.getMonth() + 1;
	
				//获取当前日
				var date = myDate.getDate();
				var h = myDate.getHours(); //获取当前小时数(0-23)
				var m = myDate.getMinutes(); //获取当前分钟数(0-59)
				var s = myDate.getSeconds();
	
			   //获取当前时间
				if(type=="date"){
					var now = year + '-' + this.conver(month) + "-" + this.conver(date);
				}else{
					var now = year + '-' + this.conver(month) + "-" + this.conver(date) + " " + this.conver(h) + ':' + this.conver(m) + ":" + this.conver(s);
				}
			   return now;	
			},
			//日期时间处理
			conver(s) {
			return s < 10 ? '0' + s : s;
			},
			onShowDatePicker(type){//显示
			    this.type = type;
			    this.showPicker = true;
			    this.value = this[type];
			},
			onSelected(e) {//选择
			    this.showPicker = false;
			    if(e) {
			        this[this.type] = e.value; 
			        //选择的值
			        //console.log('value => '+ e.value);
			        //原始的Date对象
			        //console.log('date => ' + e.date);
			    }
			},
			getReserveData(dayStart){
				uni.request({
					url: uni.getStorageSync('api_url')+'/statistics/getReserveInfo?shopUserId='+uni.getStorageSync('admin_id')+'&scId='+uni.getStorageSync('shop_id')+'&sdDay='+dayStart,
					method: 'get',
					header:{'content-type': 'application/x-www-form-urlencoded'},
					success: (result) => {
						 //console.log(result)
						if(result.data.code != 1){
							uni.showToast({
								title:result.data.msg,
								icon:'none'
							});
							
						}else{
							const data=result.data.data;
							this.reseve_need_count= data.reseve_need_count;//预约待处理
							this.reseve_complate_month=data.reseve_complate_month;//本月处理预约数
							this.order_need_count= data.order_need_count;//预约待处理
							this.order_complate_month=data.order_complate_month;//本月处理预约数
						}
					},
				})
			},
			getData(dayStart,dayEnd){
				
					this.cost="￥0";
					this.profit="￥0";
					this.flowAccountMonth="￥0";
					this.rechargeMonth="￥0";
					this.newMemberDay=0;
				uni.request({
					url: uni.getStorageSync('api_url')+'/statistics/getObjInfo?scKey='+uni.getStorageSync('shop_id')+'&sdDay='+dayStart+'&sdObjId='+uni.getStorageSync('sCode'),
					method: 'get',
					header:{'content-type': 'application/x-www-form-urlencoded'},
					success: (result) => {
						 //console.log(result)
						if(result.data.code != 1){
							uni.showToast({
								title:result.data.msg,
								icon:'none'
							});
							
						}else{
							const data=result.data.data;
							data.forEach((rst) => {
								if(rst.smMonth!=undefined && rst.smMonth!=""){
									if(rst.smName=='cost'){
										this.cost="￥"+parseFloat(rst.smValue).toFixed(2);
									}else if(rst.smName=='profit'){
										this.profit="￥"+parseFloat(rst.smValue).toFixed(2);
									}else if(rst.smName=='flowAccount'){
										this.flowAccountMonth="￥"+parseFloat(rst.smValue).toFixed(2);//本月店铺流水总额
									}else if(rst.smName=='recharge'){
										this.rechargeMonth="￥"+parseFloat(rst.smValue).toFixed(2);//本月会员卡充值总额
									}else if(rst.smName=='newMember'){
										this.newMemberDay=parseInt(rst.smValue);//新增会员数
									}
									//else if(rst.smName=='memberNum'){
									//	this.memberNum=parseInt(rst.smValue);//会员总数
									//}
								}
							});
						}	
					}
				});
			},
			getAllMemberNum(){
				uni.request({
					url: uni.getStorageSync('api_url')+'/member/getList?page=1&perPage=1&mcKey='+uni.getStorageSync('shop_id'),
					method: 'get',
					header:{'content-type': 'application/x-www-form-urlencoded'},
					success: (result) => {
						 //console.log(result)
						if(result.data.code != 1){
							uni.showToast({
								title:result.data.msg,
								icon:'none'
							});
						}else{						
							this.memberNum = result.data.data.count;
						}	
					}
				});
			},
			getShopCode(){
				uni.request({
					url: uni.getStorageSync('api_url')+'/store/get/'+uni.getStorageSync('shop_id'),
					method: 'get',
					header:{'content-type': 'application/x-www-form-urlencoded'},
					success: (result2) => {
						uni.setStorageSync('sCode',result2.data.data.sCode);
					},
				});
			}
		},
	}
</script>

<style scoped>
	.data-title{
	        float: left;
	        color: #ffffff;
	        font-size: 16px;
	        padding: 0px 20px;
		}
	
	.location{
		background-color: #ffffff;
		display: flex;
		justify-content: center;
		padding: 8px;
		box-shadow: 0px 0px 5px #888888;
	}
	.home-img{
		width: 30px;
		height: 30px;
		float: left;
	    margin-left: 0.5rem;
	}
	.home-title{
		    width: 70%;
		    float: left;
		    text-align: center;
		    font-size: 18px;
		    line-height: 30px;
			}
	.img-list{
		width: 1.8rem;
		height:1.8rem;
	}
	.list{
		width: 100%;
		margin: 1.2rem 0;
		display:flex;
		justify-content: space-around;
		}
	a{
		text-decoration: none;
	} 
	.list-top{
		font-size: 14px;
		text-align: center;
	}
	.arrows{
		float: right;
		color:#FFFFFF;
		font-size: 16px;
		padding: 0px 20px;
	}
	.statistical{
		width: 96%;
		margin-left: auto;
		margin-right: auto;
		display: block;
		border-radius:5px;
		background-color: #ffffff;
		margin-bottom: 1.5rem;
		box-shadow: 0px 0px 5px #6d1c79;
		min-height: 360upx;
	}
	.statistical-title{
		width: 100%;
		height:2rem;
		line-height: 2rem;
		padding: 5px 0;
		border-radius:5px 5px 0 0 ;
		background: linear-gradient(to right bottom,#fb4386,#ec4fae,#ce63d0,#a377ea,#6488f9);
	}
    .statistical-data{
	    width: 50%;
		margin: 0.6rem 0px;
		font-size: 14px;
		text-align: center;
		float: left;
		
		box-sizing: border-box;
	}
	 .statistical-data:nth-of-type(even){
		 border-right: 1px solid #ccc;
	 }
</style>
